<template>
  <BasicModal v-bind="$attrs" @register="registerModal" destroyOnClose :title="title" :width="props.width"
    height="250" @ok="handleSubmit">
    <a-row>
      <a-col :span="22">
        <BasicForm @register="registerForm" />
      </a-col>
    </a-row>
  </BasicModal>
</template>

<script lang="ts" setup>
import { ref, computed, unref } from 'vue';
import { BasicModal, useModalInner } from '/@/components/Modal';
import { BasicForm, useForm } from '/@/components/Form/index';
import { FormSchema } from '/@/components/Table';
// Emits声明
const emit = defineEmits(['register', 'success']);
const isUpdate = ref(false);
import AllModal from '/@/views/xl/customer_orde/components/AllModal.vue'
import { useMessage } from "/@/hooks/web/useMessage";
const { createConfirm, createMessage } = useMessage();
//页面属性
const props = defineProps({
  width: { type: Number, default: 600 },
  height: { type: Number, default: 120 },
  schemas: { type: Array as PropType<FormSchema[]> },
  apiUrl: { type: Function as PropType<Fn> },
  pid: { require: true, type: String },
});

var title = ref('凭证提交');

//表单配置
const [registerForm, { setProps, resetFields, setFieldsValue, validate }] = useForm({
  labelWidth: 130,
  schemas: props.schemas,
  showActionButtonGroup: false,
  baseColProps: { span: 24 },
});

var ids = ref([]);
//表单赋值
const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
  //重置表单
  await resetFields();
  //表单赋值
  setFieldsValue({
    asId: data?.record?.asId,
    refundAmount: data?.record?.productTotalAmount,
  });
});
//表单提交事件
async function handleSubmit(v) {
  try {
    setModalProps({ confirmLoading: true });
    let values = await validate();
    if (values.asStatus == '同意') {
      
      createConfirm({
        title: '退款确认',
        content: `确定要退款 ${values.refundAmount} 元?`,
        iconType: 'warning',
        okText: '确认退款',
        cancelText: '取消退款',
        onOk: () => {
          props.apiUrl(values);
          //关闭弹窗
          closeModal();
          //刷新列表
          emit('success');
          return true;
        }
      });

    } else {
      //提交表单
      await props.apiUrl(values);
      //关闭弹窗
      closeModal();
      //刷新列表
      emit('success');
    }
    
  } finally {
    setModalProps({ confirmLoading: false });
  }
}
</script>

<style lang="less" scoped>
/** 时间和数字输入框样式 */
:deep(.ant-input-number) {
  width: 100%;
}

:deep(.ant-calendar-picker) {
  width: 100%;
}
</style>
